package com.boang.service;

import com.boang.domain.bo.Sms;
import com.boang.resp.Result;
import com.boang.utils.HttpUtils;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/*
  @author: 13813
  @date: 2024/9/5 9:50
*/
@Service
public class AliyunSmsServiceImpl implements SmsService {

    @Autowired
    private Sms sms;

    @Override
    public Result<String> sendSms(String phone, int code) throws Exception {
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + sms.getAppcode());
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("mobile", phone);
        querys.put("param", "**code**:" + code + ",**minute**:5");
        querys.put("smsSignId", sms.getSmsSignId());
        querys.put("templateId", sms.getTemplateId());
        Map<String, String> bodys = new HashMap<String, String>();
        HttpResponse response = HttpUtils.doPost(sms.getHost(), sms.getPath(), method, headers, querys, bodys);
        response.getStatusLine().getStatusCode();
        return Result.ok();
    }
}
